using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class JobSeekers_jobsearch : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (!IsPostBack)
            ShowData();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ShowData();
        GridView1.PageIndex = e.NewPageIndex;
    }
    void ShowData()
    {
        try
        {
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPViewSavedSearch";
            cls.ParameterCollection = new string[1] { "@UserID"};
            cls.ValueCollection = new string[1] { 
            Convert.ToString(Session.Contents["jsuserid"]) };
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToGridView(this.GridView1, 10, 10, PagerButtons.NumericFirstLast);
            this.GridView1.Columns[4].Visible = false;
            this.GridView1.Columns[6].Visible = false;
            if (GridView1.Rows.Count > 1)
                btnDelete.Enabled = true;
            else
                btnDelete.Enabled = false;
        }
        catch (Exception ex)
        {
            Literal1.Text = ex.Message;
        }
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    { 
        Server.Transfer("jobresult.aspx?indexRow=" + e.RowIndex);
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string searchID = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkSearchID");
            if (checkBox.Checked)
            {
                try
                {
                    searchID +=
                    gridViewRow.Cells[1].Text + ",";
                }
                catch (Exception ex)
                {
                    Literal1.Text = ex.Message;
                }
            }

        }
        if (searchID != "")
        {
            searchID = searchID.Substring(0, searchID.Length - 1);
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string search in searchID.Split(','))
                sqlServerProvider.DeleteSavedSearch(
                Convert.ToString(Session["jsuserid"]), search);
            ShowData();
        }
    }
}
